package com.ssoserver.service.impl;

import com.ssoserver.annotation.MyDataSource;
import com.ssoserver.mapper.UserMapper;
import com.ssoserver.pojo.User;
import com.ssoserver.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @MyDataSource("slave0")
    public List<User> findAll() {
        List<User> all1 = ((UserServiceImpl) AopContext.currentProxy()).findAll1();
        List<User> all = userMapper.findAll();
        all1.addAll(all);
        return all1;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @MyDataSource("slave1")
    public List<User> findAll1(){
        return userMapper.findAll();
    }
    /**
     * @param s
     * @return
     * @author Eilen
     * 查询该用户是否存在
     */
    @Override
    public Integer findByUserName(String s) {
        return userMapper.findByUserName(s);
    }

    @Override
    public Integer findByPassword(CharSequence rawPassword) {
        return userMapper.findPassword(rawPassword);
    }

}
